/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package general.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import jpa.controller.FornecedorJpaController;
import jpa.entity.Fornecedor;
/**
 *
 * @author isaias
 */
@FacesConverter(value="fornecedorConverter")
public class FornecedorConverter implements Converter{

    public Object getAsObject(FacesContext fc, UIComponent uic, String name) {

        Fornecedor fornecedor = new FornecedorJpaController().findFornecedorForName(name);

        return fornecedor;
    }

    public String getAsString(FacesContext fc, UIComponent uic, Object o) {

        if(o instanceof Fornecedor){
            return ((Fornecedor)o).getName();
        }

        return null;
    }
}
